package com.yl.chainStore.entity.warehouse

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.yl.chainStore.common.enums.Status
import com.yl.chainStore.util.GenerateNum
import com.yl.common.annotation.NoArg
import com.yl.common.getContext
import com.yl.users.common.NeedGerId
import java.util.*

/**
 * <p>
 * 盘点单
 * </p>
 *
 * @author cxw
 * @since 2021-06-10
 */
@NoArg
@TableName("warehouse_check_order")
class WarehouseCheckOrder(
    /**
     *  盘点表
     */
    @TableId(value = "id", type = IdType.AUTO)
    var id: Long,

    /**
     * 公司id
     */
    @TableField("company_id")
    var companyId: Long = getContext().companyId,

    /**
     * 部门id
     */
    @TableField("dept_id")
    var deptId: Long = getContext().subCompanyId,

    @TableField(exist = false)
    var deptName: String? = null,

    /**
     * 创建人id
     */
    @TableField("create_user_id")
    var createUserId: Long = getContext().userId,

    @TableField(exist = false)
    var createUserName: String? = null,

    /**
     * 盘点人
     */
    @TableField("check_user_id")
    var checkUserId: Long? = createUserId,

    @TableField(exist = false)
    var checkUserName: String? = null,

    /**
     * 处理人
     */
    @TableField("deal_user_id")
    var dealUserId: Long? = null,

    @TableField(exist = false)
    var dealUserName: String? = null,

    /**
     * 创建时间
     */
    @TableField("create_time")
    var createTime: Date = Date(),

    /**
     * 盘点时间
     */
    @TableField("check_time")
    var checkTime: Date = Date(),

    /**
     * 审核时间
     */
    @TableField("deal_time")
    var dealTime: Date? = null,

    /**
     * 状态
     */
    @TableField("status")
    var status: Status = Status.UNKNOWN,

    /**
     * 盘点单号
     */
    @TableField("check_num")
    var checkNum: String = generateOrder("C"),

    /**
     * 数据有效性
     */
    @TableField("enabled")
    var enabled: Int = 1,

    @TableField("remark")
    var remark:String?= null,

    @TableField(exist = false)
    var details: List<WarehouseCheckOrderDetail>? = null,
){
    val orderIsSelf: Boolean
        get() {
            return createUserId == getContext().userId
        }

    companion object : GenerateNum()

}
